package com.sz.app.oss.api.system.dto;

import com.sz.common.core.service.role.MembershipType;
import com.sz.common.core.service.role.RoleMembership;

import java.util.ArrayList;
import java.util.List;

/**
 * Function: AssignMemberDto <br>
 * Author: wentao.chang <br>
 * Date: 2016-12-16 10:28:00
 */
public class AssignMemberDto {
    private List<Integer> userIds = new ArrayList<>();
    private List<Integer> orgIds = new ArrayList<>();
    private List<Integer> userGroupIds = new ArrayList<>();

    public List<Integer> getUserIds() {
        return userIds;
    }

    public void setUserIds(List<Integer> userIds) {
        this.userIds = userIds;
    }

    public List<Integer> getOrgIds() {
        return orgIds;
    }

    public void setOrgIds(List<Integer> orgIds) {
        this.orgIds = orgIds;
    }

    public List<Integer> getUserGroupIds() {
        return userGroupIds;
    }

    public void setUserGroupIds(List<Integer> userGroupIds) {
        this.userGroupIds = userGroupIds;
    }


    public List<RoleMembership> getRoleMemberships() {
        List<RoleMembership> list = new ArrayList<>();
        if (this.getOrgIds().size() > 0) {
            this.getOrgIds().forEach(id ->
                    list.add(new RoleMembership(id, MembershipType.ORGANIZATION)));
        }
        if (this.getUserGroupIds().size() > 0) {
            this.getUserGroupIds().forEach(id ->
                    list.add(new RoleMembership(id, MembershipType.USER_GROUP)));
        }
        if (this.getUserIds().size() > 0) {
            this.getUserIds().forEach(id ->
                    list.add(new RoleMembership(id, MembershipType.USER)));
        }
        return list;
    }
}
